package com.example.zzh.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.zzh.entity.*;
import com.example.zzh.service.ZzhDepotService;
import com.example.zzh.service.ZzhProductService;
import com.example.zzh.service.ZzhProductStockService;
import com.example.zzh.utils.Result;
import com.example.zzh.utils.ResultGenerator;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 产品当前库存 前端控制器
 * </p>
 *
 * @author zzh
 * @since 2023-08-14
 */
@RestController
@RequestMapping("/zzh-product-stock")
public class ZzhProductStockController {
    @Autowired
    private ZzhProductStockService zzhProductStockService;

    @Autowired
    private ZzhProductService zzhProductService;

    @Autowired
    private ZzhDepotService zzhDepotService;

    @GetMapping("/option")
    @ApiOperation(value = "查询下拉仓库列表", notes = "查询下拉仓库列表")
    public Result option(){
        List<ZzhDepot> zzhDepots=zzhDepotService.list();
        Map<Long,String> hashMapDepots=new HashMap<Long, String>();
        for (ZzhDepot i : zzhDepots) {
            hashMapDepots.put(i.getId(), i.getName());
        }
        return ResultGenerator.genSuccessResult(hashMapDepots);
    }

    @PostMapping("/list")
    @ApiOperation(value = "查询商品总库存分页", notes = "分页")
    public Result list(@RequestBody Map<String,Object> params){
        HashMap<String,Object> hashMap=new HashMap<>();
        if (StringUtils.isEmpty(params.get("page")) || StringUtils.isEmpty(params.get("limit"))) {
            return ResultGenerator.genFailResult("参数异常！");
        }
        //分页标签
        Page<ZzhProduct> page=new Page<>();
        page.setCurrent((int) params.get("page"));
        page.setSize((int) params.get("limit"));
        if(!StringUtils.isEmpty(params.get("name"))){
            hashMap.put("name",params.get("name"));
        }
        if(!StringUtils.isEmpty(params.get("categoryId"))){
            hashMap.put("categoryId",params.get("categoryId"));
        }
        IPage r=null;
        List<ZzhProductStock> zzhProductStocks=zzhProductStockService.list();
        List<ZzhDepot> zzhDepots=zzhDepotService.list();
        List<ZzhProduct> zzhProducts=zzhProductService.list();
        

//        List<ZzhProductInfo> zzhProductInfoList=zzhProductService.selectProductList(page,hashMap);
//        for(ZzhProductInfo zzhProductInfo : zzhProductInfoList){
//            BigDecimal productStockNum = BigDecimal.valueOf(0);
//            List<ZzhProductStock> zzhProductStocks=zzhProductStockService.lambdaQuery().eq(ZzhProductStock::getMaterialId,zzhProductInfo.getId()).list();
//            for(ZzhProductStock zzhProductStock : zzhProductStocks ){
//                productStockNum=productStockNum.add(zzhProductStock.getCurrentNumber());
//            }
//            zzhProductInfo.setZzhProductStocks(zzhProductStocks);
//            zzhProductInfo.setCurrentNumber(productStockNum);
//        }


        return ResultGenerator.genSuccessResult();
    }
}
